package vshevchuk;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;

public class ds_csv extends IDS
{
	{
		name = "CSV";
	}
	
	@Override
	public void Save (ArrayList<Base> p) throws Exception 
	{
		BufferedWriter out = new BufferedWriter(new FileWriter("data.csv"));
		
		for (int i=0; i<p.size(); i++)	
		{
			//out.write(   p.get(i).toString() );
			out.write( convFactory.getInstance( "CSV" ).toString(p.get(i)) + "\r\n" );
		}
		out.close();
	}
	
	@Override
	public ArrayList<Base> Load() throws Exception 
	{
		ArrayList<Base> p= new ArrayList<Base>();
		String str;
		
		BufferedReader in = new BufferedReader(new FileReader("data.csv"));
	
		while( (str = in.readLine()) != null )
		{
			//p.add( Base.CreatClass(str,"CSV") );
			p.add( convFactory.getInstance( "CSV" ).fromString(str) );
			
		}
		in.close();
		return p;
	}
}
